﻿using System;
using System.IO;
using Antix.Mail.Smtp.Impostor;

namespace Antix.Mail.Tests
{
    public static class TestHelper
    {
        public static Host CreateForwardHost(
            this Server server, int port,
            string forwardServer, int forwardPort,
            string forwardServerUser = null, string forwardServerPassword = null,
            string from = "from@example.com", string to = "to@example.com")
        {
            return server.CreateHost(new HostConfiguration
            {
                MessageStorage = new ForwardMessageStorageConfiguration
                {
                    Server = forwardServer,
                    From = from,
                    ForwardTo = to,
                    Port = forwardPort,
                    User = forwardServerUser,
                    Password = forwardServerPassword
                },
                Port = port
            });
        }

        public static Host CreateFileHost(
            this Server server, int port,
            string path)
        {
            var dropPath = Path.Combine(Path.GetTempPath(), path);
            if (Directory.Exists(dropPath)) Directory.Delete(dropPath, true);

            Console.WriteLine(dropPath);

            return server.CreateHost(new HostConfiguration
            {
                MessageStorage = new FileMessageStorageConfiguration
                {
                    DropPath = dropPath
                },
                Port = port
            });
        }
    }
}